<?php
/**
 * 快速获得数据库的一些配置信息，如gender area, 
 * @file ConfigModel.class.php
 * @auther liyangguang
 * @date 2011-12-08
 * //TODO:
 * memcached.
 */

class ConfigModel
{
    public static function getGender($intID, $default = "") 
    {
        if (empty($intID)){return $default;}
        if (self::$_arrGenderTable == NULL) {
            $objGenderTypesTable = new GenderTypesTable();
            $arrGenderList = $objGenderTypesTable->fetchAll()->toArray();
            foreach($arrGenderList as $gender) {
                self::$_arrGenderTable[$gender['id']] = $gender['gender_name'];
            }
        }
        return self::$_arrGenderTable[$intID];
    }
    public static function getArea($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrAreaTable == NULL) {
            $objAreaTypesTable = new AreaTypesTable();
            $arrAreaList = $objAreaTypesTable->fetchAll()->toArray();
            foreach($arrAreaList as $area) {
                self::$_arrAreaTable[$area['id']] = $area['area_name'];
            }
        }
        
        return self::$_arrAreaTable[$intID];
    }
    public static function getAge($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrAgeTable == NULL) {
            $objAgeTypesTable = new AgeTypesTable();
            $arrAgeList = $objAgeTypesTable->fetchAll()->toArray();
            foreach($arrAgeList as $age) {
                self::$_arrAgeTable[$age['id']] = $age['age_name'];
            }
        }
        return self::$_arrAgeTable[$intID];
    }
    
    public static function getBody($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrBodyTable == NULL) {
            $objBodyTypesTable = new BodyTypesTable();
            $arrBodyList = $objBodyTypesTable->fetchAll()->toArray();
            foreach($arrBodyList as $body) {
                self::$_arrBodyTable[$body['id']] = $body['body_name'];
            }
        }
        return self::$_arrBodyTable[$intID];
    }
    
    public static function getExperience($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrExperienceTable == NULL) {
            $objExperienceTypesTable = new ExperienceTypesTable();
            $arrExperienceList = $objExperienceTypesTable->fetchAll()->toArray();
            foreach($arrExperienceList as $experience) {
                self::$_arrExperienceTable[$experience['id']] = $experience['experience_name'];
            }
        }
        return self::$_arrExperienceTable[$intID];
    }
    
    public static function getEdulevel($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrEdulevelTable == NULL) {
            $objEdulevelTypesTable = new EdulevelTypesTable();
            $arrEdulevelList = $objEdulevelTypesTable->fetchAll()->toArray();
            foreach($arrEdulevelList as $edulevel) {
                self::$_arrEdulevelTable[$edulevel['id']] = $edulevel['edulevel_name'];
            }
        }
        return self::$_arrEdulevelTable[$intID];
    }
    
    public static function getTrainingservice($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrTrainingserviceTable == NULL) {
            $objTrainingserviceTypesTable = new TrainingserviceTypesTable();
            $arrTrainingserviceList = $objTrainingserviceTypesTable->fetchAll()->toArray();
            foreach($arrTrainingserviceList as $trainingservice) {
                self::$_arrTrainingserviceTable[$trainingservice['id']] = $trainingservice['trainingservice_name'];
            }
        }
        return self::$_arrTrainingserviceTable[$intID];
    }
    
    public static function getGenGoal($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrGenGoalTable == NULL) {
            $objGoalTypesTable = new GoalTypesTable();
            $arrGenGoalList = $objGoalTypesTable->fetchAll()->toArray();
            foreach($arrGenGoalList as $gengoal) {
                self::$_arrGenGoalTable[$gengoal['id']] = $gengoal['goal_name'];
            }
        }
        return self::$_arrGenGoalTable[$intID];
    }
    
    public static function getClientGenGoal($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrClientGenGoalTable == NULL) {
            $objClientGenGoalTypesTable = new ClientGenGoalTypesTable();
            $arrClientGenGoalList = $objClientGenGoalTypesTable->fetchAll()->toArray();
            foreach($arrClientGenGoalList as $gengoal) {
                self::$_arrClientGenGoalTable[$gengoal['id']] = $gengoal['goal_name'];
            }
        }
        return self::$_arrClientGenGoalTable[$intID];
    }
    
    public static function getStatus($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrStatusTable == NULL) {
            $objStatusTypesTable = new StatusTypesTable();
            $arrStatusList = $objStatusTypesTable->fetchAll()->toArray();
            foreach($arrStatusList as $status) {
                self::$_arrStatusTable[$status['id']] = $status['status_name'];
            }
        }
        return self::$_arrStatusTable[$intID];
    }
    
    public static function getSearchGoalStatus($intID)
    {
        if (empty($intID)){return;}
        if ($intID <= 2) {
            return 'Open to bid';
        }
        else if ($intID <= 4){
            return 'Trainer selected';
        }
        else {
            return 'Closed';
        }
    }
    
    public static function getRole($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrRoleTable == NULL) {
            $objRoleTypesTable = new RoleTypesTable();
            $arrRoleList = $objRoleTypesTable->fetchAll()->toArray();
            foreach($arrRoleList as $role) {
                self::$_arrRoleTable[$role['id']] = $role['role_name'];
            }
        }
        return self::$_arrRoleTable[$intID];
    }
    
    public static function getTrainerType($intID, $default = "")
    {
        if (empty($intID)){return $default;}
        if (self::$_arrTrainerTypeTable == NULL) {
            $objTrainerTypesTable = new TrainerTypesTable();
            $arrTrainerList = $objTrainerTypesTable->fetchAll()->toArray();
            foreach($arrTrainerList as $trainer) {
                self::$_arrTrainerTypeTable[$trainer['id']] = $trainer['trainer_name'];
            }
        }
        if (!isset(self::$_arrTrainerTypeTable[$intID])) {
            return $default;
        }
        return self::$_arrTrainerTypeTable[$intID];
    }
    
    public static function getSessionType($intID, $default = "")
    {
        
        if (empty($intID)){return $default;}
        if (self::$_arrSessionTypeTable == NULL) {
            $objSessionTypesTable = new SessionTypesTable();
            $arrSessionList = $objSessionTypesTable->fetchAll()->toArray();
            foreach($arrSessionList as $session) {
                self::$_arrSessionTypeTable[$session['id']] = $session['session_name'];
            }
        }
        return self::$_arrSessionTypeTable[$intID];
    }
    
    public static function getCredentialType($intID, $default = "")
    {
        
        if (empty($intID)){return $default;}
        if (self::$_arrCredentialTypeTable == NULL) {
            $objCredentialTypesTable = new CredentialTypesTable();
            $arrCredentialList = $objCredentialTypesTable->fetchAll()->toArray();
            foreach($arrCredentialList as $credential) {
                self::$_arrCredentialTypeTable[$credential['id']] = $credential['credential_name'];
            }
        }
        return self::$_arrCredentialTypeTable[$intID];
    }
    
    public function genUsername($strFirstname, $strLastname)
    {
        $strUsername = $strFirstname . ' ' . strtoupper(substr($strLastname, 0, 1));
        return $strUsername;
    }
    
    public function getNextStep($intStatus)
    {
        $intStatus = intval($intStatus);
        $strStep = '';
        switch ($intStatus) {
            case GoalModel::GOAL_STATUS_POSTED:
                $strStep = 'Wait for offers';
                break;
            case GoalModel::GOAL_STATUS_BIDED:
                $strStep = 'Select (award) bids';
                break;
            case GoalModel::GOAL_STATUS_AWARDED:
                $strStep = 'Training scheduled';
                break;
            case GoalModel::GOAL_STATUS_REVIEWED:
                $strStep = 'Reach your goal';
                break;
            case GoalModel::GOAL_STATUS_REACHED:
                $strStep = 'Nothing to do';
                break;
        }
        return $strStep;
    }
    

    
    protected static $_arrAgeTable = null;
    protected static $_arrBodyTable = null;
    protected static $_arrGenderTable = null;
    protected static $_arrAreaTable = null;
    protected static $_arrExperienceTable = null;
    protected static $_arrServiceTable = null;
    protected static $_arrEdulevelTable = null;
    protected static $_arrTrainingserviceTable = null;
    protected static $_arrGenGoalTable = null;
    protected static $_arrClientGenGoalTable = null;
    protected static $_arrStatusTable = null;
    protected static $_arrTrainerTypeTable = null;
    protected static $_arrSessionTypeTable = null;
    protected static $_arrCredentialTypeTable = null;
    protected static $_arrRoleTable = null;
}

?>
